$(function () {

    $("body").on("click",".delivery",function(){
      var that =  $(this);
        var id =    $(this).data("id");
        var name =    $(this).data("name");
        var userId =    $(this).data("userid");
        var shopId =  $('input[name="id"]').val();
        var index = parent.layer.open({
            type: 1,
            area: ['500px'],
            skin: 'layui-layer-demo',
            title: '填写快递单号',
            content: '<div class="m-t m-r m-l m-b"><input class="form-control" placeholder="请填写快递单号"  value="" id="number" name="number" type="text"><br>' +
                '<input class="form-control" placeholder="发送提醒的内容，如 您兑换的xx商品已发货，xx快递，快递单号为123456789" value="" id="content" name="content" type="text">' +
                '</div>',
            btn: '确定',
            yes: function (index, layero) {
                var courierNumber = layero.find('#number').val();
                if(courierNumber==null){
                    return icModale(0, "请输入快递单号");
                }
                var content = layero.find('#content').val();

                if(content.length>500){
                    icModale(0, "不可超过500字符");
                    return
                }
                var params ={};
                params.id=id;
                params.content=content;
                params.name=name;
                params.courierNumber=courierNumber;
                params.shopId=shopId;
                params.userId=userId;
                params = JSON.stringify(params);
                $.ajax({
                    url:  baseloaction + "/admin/IntegralGood/toSendExpress",
                    type: "post",
                    data:params,
                    dataType: "json",
                    contentType: 'application/json;charset=utf-8',
                    success: function (result) {
                        icModale(0, result.message);
                        if (result.success == true) {
                            that.removeClass("delivery");
                            that.text("快递单号");
                            that.attr("data-original-title",courierNumber);
                            $("#statst-"+id).text("已发货");
                            parent.layer.close(index);
                        }
                    },
                    error: function (error) {
                        parent.layer.close(index);
                        icModale(0, '系统繁忙，请稍后再试');
                    }
                });
            }
        });


    }).on("click",'.address',function(){
        var address =$(this).data("address");
        parent.layer.alert(address);
    });




    listCourse(1)

    lazyCourseImage();

});

//加载课程数据
function listCourse(page) {
    var params = {};
    params.integralShopId=$('input[name="id"]').val();
    params = JSON.stringify(params);
    var obj = {
        url: baseloaction + '/admin/IntegralGood/integralExchangeRecordList',//请求URL
        contextId: 'course-list-context',//响应内容页面设置内容ID
        params: params,//请求参数
        pageNo: page,//页码
        pageCall: listCourse, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
        selectAllId: 'all-course', //全选框ID
        callback: function () {//数据加载完成回调
            lazyCourseImage();
        }
    };
    ajaxGetListData(obj);
}


function lazyCourseImage() {
    //图片数据懒加载
    $('img.lazy').lazyload({
        placeholder: staticPath + '/front/web/v3/img/default/default-course.gif',  //占位图
        effect: 'fadeIn',//载入方式
        threshold: 20, // 提前开始加载
    });
}




